﻿namespace UnityEditor
{
    using System;
    using UnityEngine;

    [CustomEditor(typeof(RenderTexture)), CanEditMultipleObjects]
    internal class RenderTextureInspector : TextureInspector
    {
        private static GUIContent[] kRenderTextureDepths = new GUIContent[] { new GUIContent("None"), new GUIContent("16 bit"), new GUIContent("24 bit") };
        private static int[] kRenderTextureDepthsValues;
        private static GUIContent[] kRenderTextureSizes = new GUIContent[] { new GUIContent("16"), new GUIContent("32"), new GUIContent("64"), new GUIContent("128"), new GUIContent("256"), new GUIContent("512"), new GUIContent("1024"), new GUIContent("2048") };
        private static int[] kRenderTextureSizesValues = new int[] { 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800 };
        private static string[] kTextureFormatsStrings;
        private SerializedProperty m_DepthFormat;
        private SerializedProperty m_Height;
        private SerializedProperty m_Width;

        static RenderTextureInspector()
        {
            int[] numArray1 = new int[3];
            numArray1[1] = 1;
            numArray1[2] = 2;
            kRenderTextureDepthsValues = numArray1;
            kTextureFormatsStrings = new string[] { 
                "RGBA 32bit", "Depth", "RGBA 64bit FP", "Shadowmap", "RGB 16bit", "RGBA 16bit", "RGBA 16bit (5-1)", string.Empty, "RGBA 32bit (10-2)", string.Empty, "RGBA 64bit", "RGBA 128bit FP", "RG 64bit FP", "RG 32bit FP", "R 32bit FP", "R 16bit FP", 
                "R 8bit"
             };
        }

        public override string GetInfoString()
        {
            RenderTexture target = base.target as RenderTexture;
            string str = target.width.ToString() + "x" + target.height.ToString();
            if (!target.isPowerOfTwo)
            {
                str = str + "(NPOT)";
            }
            return ((str + "  " + kTextureFormatsStrings[(int) target.format]) + "  " + EditorUtility.FormatBytes(TextureUtil.GetRuntimeMemorySize(target)));
        }

        protected override void OnEnable()
        {
            base.OnEnable();
            this.m_Width = base.serializedObject.FindProperty("m_Width");
            this.m_Height = base.serializedObject.FindProperty("m_Height");
            this.m_DepthFormat = base.serializedObject.FindProperty("m_DepthFormat");
        }

        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            RenderTexture target = base.target as RenderTexture;
            if (target.isPowerOfTwo)
            {
                GUI.changed = false;
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                EditorGUILayout.PrefixLabel("Size", "MiniPopup");
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinWidth(40f) };
                EditorGUILayout.IntPopup(this.m_Width, kRenderTextureSizes, kRenderTextureSizesValues, GUIContent.none, options);
                GUILayout.Label("x", new GUILayoutOption[0]);
                GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MinWidth(40f) };
                EditorGUILayout.IntPopup(this.m_Height, kRenderTextureSizes, kRenderTextureSizesValues, GUIContent.none, optionArray2);
                GUILayout.FlexibleSpace();
                GUILayout.EndHorizontal();
                EditorGUILayout.IntPopup(this.m_DepthFormat, kRenderTextureDepths, kRenderTextureDepthsValues, EditorGUIUtility.TempContent("Depth Buffer"), new GUILayoutOption[0]);
                if (GUI.changed)
                {
                    target.Release();
                }
            }
            base.isInspectorDirty = true;
            base.serializedObject.ApplyModifiedProperties();
            EditorGUILayout.Space();
            base.OnInspectorGUI();
        }
    }
}

